<template>
  <div class="tab-switcher" :class="[theme]">
    <div 
      v-for="(tab, index) in tabs" 
      :key="index" 
      class="tab-item"
      :class="[{ 'active': activeTab === index }, `tab-item${index + 1}`, { 'tab-item-left': activeTab === 2 && index === 1}, { 'tab-item-right': activeTab === 0 && index === 1}]"
      @click="handleTabClick(index)"
    >
      <div class="tab-content">
        <div v-if="tab.icon" class="tab-icon">
          <i :class="tab.icon"></i>
        </div>
        <div class="tab-label">{{ tab.label }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';
import { useAppStore } from '../../store/app'
import { storeToRefs } from 'pinia';

const { theme } = storeToRefs(useAppStore());

const props = defineProps({
  tabs: {
    type: Array,
    required: true,
    default: () => [
      { label: '快速充值' },
      { label: '充值列表' },
      { label: '余额记录' }
    ]
  },
  activeTab: {
    type: Number,
    default: 0
  },
});

const emit = defineEmits(['tab-change']);

const handleTabClick = (index) => {
  emit('tab-change', index);
};
</script>

<style lang="scss" scoped>
.tab-switcher {
  display: flex;
  padding: 4px;
  border-radius: 12px;
  transition: all 0.3s ease;
  align-items: flex-end;
  position: relative;
  overflow: visible;
  &.rounded {
    border-radius: 12px;
  }
}

.tab-item {
  flex: 1;
  text-align: center;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
  position: relative;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 -12px;
  z-index: 1;
  background-size: 100%;
  background-repeat: no-repeat;  
  color: #AAAAAA;
  
  &.active {
    z-index: 100;
    height: 56px;
    background-size: 100%;
    // transform: translateY(1px);
    font-weight: 600;
    
    .tab-content {
      background: -webkit-linear-gradient(90deg, #EEEEEE 0%, #FFF5C2 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }
}

.dark {
  .tab-item {
    background-size: 100% 100%;
  }
  .tab-item1 {
    background-image: url('../../assets/imgs/images/tab/tab-1.png');
    &.active {
      background-image: url('../../assets/imgs/images/tab/tab-active1.png');
    }
  }
  
  .tab-item2 {
    z-index: 4;
    &.active {
      background-image: url('../../assets/imgs/images/tab/tab-active2.png');
    }
    &.tab-item-left {      
      background-image: url('../../assets/imgs/images/tab/tab-2-left.png');
      transform: translateX(-5px);
    }
    &.tab-item-right {      
      background-image: url('../../assets/imgs/images/tab/tab-2-right.png');
      transform: translateX(5px);
    }
  }
  
  .tab-item3 {
    background-image: url('../../assets/imgs/images/tab/tab-3.png');
    &.active {
      background-image: url('../../assets/imgs/images/tab/tab-active3.png');
      background-size: 120% 100%;
      transform: translateY(1px);
    }
  }
}

.light {
  .tab-item {
    background-size: 100% 100%;
  }
  .active {
    .tab-content {
      background: linear-gradient(90deg, #333333 0%, #000000 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }
  
  .tab-item1 {
    background-image: url('../../assets/imgs/images/tab/tab-1_light.png');
    &.active {
      background-image: url('../../assets/imgs/images/tab/tab-active1_light.png');
    }
  }
  
  .tab-item2 {
    z-index: 4;
    &.active {
      background-image: url('../../assets/imgs/images/tab/tab-active2_light.png');
    }
    &.tab-item-left {      
      background-image: url('../../assets/imgs/images/tab/tab-2-left_light.png');
    }
    &.tab-item-right {      
      background-image: url('../../assets/imgs/images/tab/tab-2-right_light.png');
    }
  }
  
  .tab-item3 {
    background-image: url('../../assets/imgs/images/tab/tab-3_light.png');
    &.active {
      background-image: url('../../assets/imgs/images/tab/tab-active3_light.png');
      background-size: 120% 100%;
    }
  }
}

.tab-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
</style>